<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

function sedit( )
{
	global $db;
	$yj_id = $_POST['id'];
	$yj_url = empty($_POST['yj_url']) ? '' : $_POST['yj_url'];
	$sql = "update yj_config  set ";

	if (!empty($_FILES['yj_img']['tmp_name'])) {
		$img_type = array("image/jpeg","image/png","image/jpg");
		/*验证*/
		if ($_FILES['yj_img']['error'] > 0) {
			echo "<script type='text/javascript'>alert('上传错误，请重试！');history.back();</script>";
			exit;
		}
		if (!in_array($_FILES['yj_img']['type'],$img_type)) {
			echo "<script type='text/javascript'>alert('图片格式不正确！！！');history.back();</script>";
			exit;
		}
		if ($_FILES['yj_img']['tmp_name'] > 204800) {
			echo "<script type='text/javascript'>alert('图片尺寸过大！！！');history.back();</script>";
			exit;
		}
		/*重命名*/
		$name_arr = explode('.', $_FILES["yj_img"]["name"]);
		$fmt = $name_arr[count($name_arr) - 1];
		$new_name = time().'.'.$fmt;
		/*上传*/
		$res = move_uploaded_file($_FILES["yj_img"]["tmp_name"],"../upload/".$new_name);

		if ($res) {
			$path = '/upload/'.$new_name;
			/*删除原图*/
			$org_data = $db->query( "Select * from yj_config where yj_id = '$yj_id'" );
			$org_data_fmt = $db->fetch_array($org_data);
			$org_path = '..'.$org_data_fmt['yj_value'];
			if (file_exists($org_path)) {
				@unlink ($org_path);
			}			
			/*更新数据*/
			$sql .= " yj_value='$path', ";
		}
	}

	$sql .= " yj_url = '$yj_url' where yj_id = '$yj_id'";
	$db->query( $sql );

	echo "<script type='text/javascript'>alert('操作完成！！');history.back();</script>";
	exit;
}

/*列表页 yjmp*/
function main()
{
		global $db;
		global $web_dbtop;
		echo "<TABLE width=\"99%\" border=0 align=center cellpadding=\"5\" cellSpacing=1 class=tbtitle style=\"BACKGROUND: #F1F1F1;\">\r\n  <TBODY>\r\n    <TR bgColor=\"#F1F1F1\">\r\n      
			<TD align=\"center\">名称</TD>\r\n     
			<TD align=\"center\">图片</TD>\r\n   
			<TD align=\"center\">操作</TD>\r\n    
			</TR>\r\n\t";


		$query = $db->query( "Select * from yj_config " );
		while ( $rs = $db->fetch_array( $query ) )
		{
				echo "    <TR align=\"center\" bgcolor=\"#FFFFFF\">\r\n      <TD>".$rs['yj_key'];
				echo "</TD>\r\n <td align='center'><img src= '../".$rs['yj_value']."' height = '150px;' ></td> \r\n";
				echo "<TD align=\"center\"><A href=\"admin_other_set.php?action=edit&id=";
				echo $rs['yj_id'];
				echo "\">修改</a></TD>\r\n</TR>\r\n\t";
		}
		echo "    <TR align=\"center\" bgcolor=\"#F1F1F1\">\r\n      <TD colspan=\"6\">";
		echo "</TD>\r\n    </TR>\r\n  </TBODY>\r\n</TABLE>\r\n";
}
/*编辑页 yjmp*/
function edit( )
{
	global $db;
	$query = $db->query( "Select * from yj_config where yj_id={$_GET['id']}" );
	if ( $rs = $db->fetch_array( $query ) )
	{
		$_html['active'] = $rs['tg_active'];
		echo "<form action=\"?action=sedit\" method=\"post\" enctype='multipart/form-data' >\r\n
			<input name=\"id\" type=\"hidden\" value=". $rs['yj_id']." />\r\n
			<TABLE width=\"99%\" border=0 align=center cellpadding=\"4\" cellSpacing=1 class=tbtitle style=\"BACKGROUND: #F1F1F1;\">\r\n
		<TBODY>\r\n<TR>\r\n <TD vAlign=center width=\"20%\" bgColor=#F1F1F1>位置：</TD>\r\n      <TD bgColor=#ffffff><INPUT id=\"title\" size=50 value=".$rs['yj_key']." name=\"yj_key\" dataType=\"Require\" msg=\"请填写标题\" readonly='readonly'>\r\n</TD>\r\n</TR>\r\n";
		echo "<tr><td>图片:</td><td><input type = 'file' name = 'yj_img' id = 'yj_img'></td></tr>";
		echo "<tr><td>url:</td><td><input type = 'text' name = 'yj_url' id = 'yj_url' value=".$rs['yj_url']."></td></tr>";
		echo"<TR align=\"center\" bgcolor=\"#F1F1F1\">\r\n <TD colspan=\"2\"><INPUT class=inputbut type=submit value=修改 name=Submit>\r\n &nbsp;</TD>\r\n</TR>\r\n  </TBODY>\r\n</TABLE>\r\n  </form>";
	}
}

include_once( dirname( __FILE__ )."/inc/conn.php" );
include_once( dirname( __FILE__ )."/inc/function.php" );
login_check( "system" );
echo "<!DOCTYPE HTML>\r\n<HTML>\r\n<HEAD>\r\n<TITLE>网站活动--后台管理系统</TITLE>\r\n<META http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n<LINK href=\"images/css_body.css\" type=text/css rel=stylesheet>\r\n<META content=\"MSHTML 6.00.3790.4275\" name=GENERATOR>\r\n</HEAD>\r\n<BODY>\r\n<DIV class=bodytitle>\r\n<DIV class=bodytitleleft></DIV>\r\n<DIV class=bodytitletxt>图片设置</DIV>\r\n";


switch ( $_GET['action'] )
{
case "edit" :
		edit( );
		break;
case "sedit" :
		sedit( );
		echo "<script type='text/javascript'>alert('修改成功');history.back();</script>";
		break;
default :
		main( );
}

echo "</BODY></HTML>\r\n";

?>

